package com.ruoyi.ex.domain;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import lombok.*;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;

import java.lang.reflect.Array;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 题目对象 ex_question
 *
 * @author zzx
 * @date 2023-03-23
 */
@AllArgsConstructor
@NoArgsConstructor
@Data
@Builder
@ToString
public class ExQuestion extends BaseEntity {
    private static final long serialVersionUID = 1L;

    /**
     * 主键
     */
    private Long id;

    /**
     * 题库编号
     */
    @Excel(name = "题库编号")
    private Long bankId;

    /**
     * 内容
     */
    @Excel(name = "内容")
    private String content;

    /**
     * 类型
     */
    @Excel(name = "类型")
    private String type;

    /**
     * 选项
     */
    @Excel(name = "选项")
    private String options;
    private List<AnswerVo> optionList;

    /**
     * 答案
     */
    @Excel(name = "答案")
    private String answers;
    private List<Character> answerList;

    /**
     * 说明
     */
    @Excel(name = "说明")
    private String info;

    /**
     * 分析
     */
    @Excel(name = "分析")
    private String analyse;

    /**
     * 机构编号
     */
    private Long deptId;

    /**
     * 预留字段1
     */
    private String reservedOne;

    /**
     * 预留字段2
     */
    private String reservedTwo;

    public void setOptions(String options) {
        this.options = options;
        this.optionList = JSONUtil.toList(options, AnswerVo.class);
    }


    public void setAnswers(String answers) {
        this.answers = answers;
        this.answerList = JSONUtil.toList(answers,Character.class);
    }

    public ExQuestion parseOptions() {
        if (ObjectUtil.isNotEmpty(this.optionList)){
            this.options = this.optionList.toString();
            JSONArray arr = new JSONArray();
            for (AnswerVo o : this.optionList) {
                if (o.getR()){arr.add(o.getK());}
            }
            this.answers = arr.toString();
        }
        return this;
    }

}
